package sliceTest

import "fmt"

// range 值类型时 K,V 是一次值拷贝。
// range 指针类型时 V是指向range对象某个值的指针的拷贝。
func r1() {
	a := [...]int{1, 2, 3, 4, 5, 6, 7, 8}
	for i, v := range a {
		a[3] = 100
		if i == 3 {
			fmt.Println("R1-->IndexValueArray", i, v)
		}
	}
	fmt.Println("R1--->:", a)
}

func r2() {
	a := []int{1, 2, 3, 4, 5, 6, 7, 8}
	for i, v := range a {
		a[3] = 100
		if i == 3 {
			fmt.Println("R2--->IndexValueArrayPtr", i, v)
		}
	}
	fmt.Println("R2--->", a)
}

func r3() {
	a := [...]int{1, 2, 3, 4, 5, 6, 7, 8}
	for i, v := range &a {
		a[3] = 100
		if i == 3 {
			fmt.Println("R3---->IndexValueArrayPtr", i, v)
		}
	}
	fmt.Println("R3---->", a)
}

func r4() {
	numbers1 := []int{1, 2, 3, 4, 5, 6}
	for i := range numbers1 {
		if i == 3 {
			numbers1[i] |= i
		}
	}
	fmt.Println(numbers1)
}

func RangeTest() {
	r1()
	r2()
	r3()
	//r4()
}
